function threshold=policy_finder(alg)

global STATES_MAX

threshold=[STATES_MAX,STATES_MAX,STATES_MAX,STATES_MAX];

for buffer=1:4
    
        i=0;
        done=0;
        while done==0 && i<STATES_MAX
        i=i+1;
           if alg.Q(i,buffer,1)<alg.Q(i,buffer,2)
           threshold(buffer)=i-1; % threshold is the prod count (hence (i-1))
           done=1;
           end
        end
        
end

